<template>
  <basic-container>

    <el-row style="margin-bottom: 20px;margin-top: 30px">
      <el-alert
        title="注意：密码必须由字母与数字组合
为了保证您的账户安全，提现与钻石转账等操作需要使用安全密码进行确认(请不要与登录密码一样)"
        type="info"
        show-icon>
      </el-alert>

    </el-row>


    <el-row>
      <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="8">
        <el-form  :model="formLabelAlign" :rules="rules" label-width="80px" class="demo-ruleForm"  ref="ruleForm">
          <el-form-item  label="新密码" prop="newPassword" >
            <el-input v-model="formLabelAlign.newPassword"  autocomplete="off" clearable type="password"
                      placeholder="请输入新密码"></el-input>
          </el-form-item>
          <el-form-item   label="确认密码" prop="confirmPassword" >
            <el-input v-model="formLabelAlign.confirmPassword"  autocomplete="off" clearable type="password"
                      placeholder="请输入确认密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit('ruleForm')">保存</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>

  </basic-container>
</template>

<script>
import {setUpPassword} from "@/api/system/user";

export default {
  name: "setpass",
  data() {
    let validPassword = (rule, value, callback) => {
      let reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{4,20}$/
      if (!reg.test(value)) {
        callback(new Error('密码必须是由4-20位字母+数字组合'))
      } else {
        callback()
      }
    };
    return {
      formLabelAlign: {
        oldPassword: '',
        newPassword: '',
        confirmPassword: ''
      },
      rules: {
        oldPassword:[
          {required: true, message: '旧密码输入格式不正确', trigger: 'blur'}
        ],
        newPassword:[
          {required: true, message: '新密码输入格式不正确', trigger: 'blur'},
          {validator: validPassword, trigger: 'blur'}
        ],
        confirmPassword:[
          {required: true, message: '新密码输入格式不正确', trigger: 'blur'},
          {validator: validPassword, trigger: 'blur'}
        ]
      },
    }
  },
  methods:{
    onSubmit(ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          setUpPassword(this.formLabelAlign.newPassword,this.formLabelAlign.confirmPassword).then(res => {
            if (res.data.success) {
              this.$message({
                type: "success",
                message: "重置密码成功!"
              });
              this.nowload();
            } else {
              this.$message({
                type: "error",
                message: res.data.msg
              });
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
